import {
    request
} from '@/common/service/request'
export default {
    //更新用户信息
    async getUserInfo({
        state,
        commit
    }) {
		
        const res = await request('user', 'info');
		
        if (res.code === 1) {
            commit('setStateAttr', {
                key: 'userInfo',
                val: res.data
            })
        }
    },

	async gettownList({
		state,
		commit
	}){
		let townList = []
		await request('common', 'getAreaList').then(
					
					res=>{
						
						if (res.code == 1) {
							
							request('common','getTownList',{
								CountyCode:res.data.CityCode
							}).then(
								res=>{
									if (res.code == 1) {
										res.data.rows.forEach(i=>{
											townList.push({
												'value':i.AreaCode,
												
												'label':i.AreaName,
												'children':[]
											})
										})
										
										townList.forEach(j=>{
											
											request('common','getVillageList',{
												TownCode:j.value
											}).then(
												res=>{
													if(res.code==1){
														
														res.data.rows.forEach(i=>{
															j.children.push({
																'value':i.AreaCode,
																
																'label':i.AreaName,
																'children':[]
																/* {value:'131125100234',label:'01'},{value:'131125100234',label:'02'} */
															})
														})
														/* 第三级列表 */
														j.children.forEach(k=>{
															
															request('common','getVillageList',{
																TownCode:k.value
															}).then(
																res=>{
																	if(res.code==1){
																		
																		res.data.rows.forEach(i=>{
																			k.children.push({
																				'value':i.AreaCode,
																				
																				'label':i.AreaName
																			})
																		})
																	}
																	
																}
															)
															
														})
														
													}
													
												}
											)
											
										})
										
									}
									
								}
							)
							
							
						}
					}
				)

		commit('setTownList', {
		    key: 'townList',
		    val: townList
		})
	}
}
